// pages/deal/deal.js
Page({
  data: {
    type:'leader',
    src:'../img/pro.jpg',
    name:'麻辣主题',
    kind:'4人套餐21.9元',
    total:"24.8",
    leave:'0',
    each:'0',
    value:'',
    much:["1","2","3","4","5","6"],
    muchindex:0,
    much2: ["2", "3", "4", "5"],
    muchindex2: 0,
    much3: ["2", "3", "4", "5"],
    muchindex3: 0,
    pin:'',
    rand:''
  },
  input: function (e) {
    this.setData({
      value: e.detail.value,
    })
   this.suan()
  },
 input2:function(e){
   var val = this.data.total - this.data.leave;
   this.setData({
     muchindex:e.detail.value,
   })
   this.suan()
 },
 input3: function (e) {
   var that=this
   var val = this.data.total;
   this.setData({
     muchindex2: e.detail.value,
   })
   var people = this.data.much2[this.data.muchindex2] 
  setTimeout(function(){
    that.setData({
      pin: (val/people).toFixed(2)
    })
  },100)
 },
 suan:function(){
   var val = this.data.total - this.data.value; 
   var people = this.data.much[this.data.muchindex] 
   var each = val/people;  
   this.setData({
     leave: val,
     each: each.toFixed(2)
   })
 },
 input4: function (e) {
   var that = this
   var val = this.data.total;
   this.setData({
     muchindex3: e.detail.value,
   })
   var people = this.data.much3[this.data.muchindex3]
   setTimeout(function () {
     that.setData({
       rand: ((Math.random()-0.5)/people*val+val/people).toFixed(2)
     })
   }, 100)
 },
 submit: function () {
   wx.navigateTo({
     url: '../pay/pay',
   })

 },
  onLoad: function (options) {
    this.setData({
      type: options.type
    })
  },
  onReady: function () {
  
  }
})